package com.ia2011.project1.domain;

import com.ia2011.project1.debug.Debug;
import com.ia2011.project1.math.Utils;

/**
 * User of the system with a personal transport
 * 
 * @author andrewk
 * 
 */
public class User extends Debug {

	private int id;
	private boolean isDriver;
	private boolean pickedUp;
	private Address home;
	private Address work;
	private Transport transport;

	public User(Integer id) {
		this.id = id;
		pickedUp = false;
		isDriver = true;
		home = new Address();
		work = new Address();
		transport = new Transport();
	}

	public User(User user) {
		this.id = user.getId();
		this.pickedUp = user.isPickedUp();
		this.isDriver = user.isDriver();
		this.home = new Address(user.getHome());
		this.work = new Address(user.getWork());
		this.transport = new Transport(user.getTransport());
	}

	public void setDriver(boolean isDriver) {
		this.isDriver = isDriver;
	}

	public boolean isDriver() {
		return isDriver;
	}

	public void setHome(Address home) {
		this.home = home;
	}

	public Address getHome() {
		return home;
	}

	public void setWork(Address work) {
		this.work = work;
	}

	public Address getWork() {
		return work;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public void setTransport(Transport transport) {
		this.transport = transport;
	}

	public Transport getTransport() {
		return transport;
	}
	
	/**
	 * Get user distance from home to work
	 * @return
	 */
	public Integer getDistance() {
		return Utils.getDistance(home.getCoords(), work.getCoords());
	}

	@Override
	public void info() {
		info("User object -> \nid: " + id + "\nisDriver: " + isDriver);
		info("User home address: ");
		home.info();
		info("User work address: ");
		work.info();
		info("User transport: ");
		transport.info();
		info("------------------------------------");
	}

	public void setPickedUp(boolean pickedUp) {
		this.pickedUp = pickedUp;
	}

	public boolean isPickedUp() {
		return pickedUp;
	}

	/**
	 * Get whole distance of the plan for driver
	 * @return
	 */
	public Double getWholeDistance() {
		Double wholeDistance = 0.0;
		for (int j=0; j < transport.getPlan().size() - 1; j++) {
			Integer distance = Utils.getDistance(transport.getPlan().get(j).getCoord(), transport.getPlan().get(j+1).getCoord());
			wholeDistance += distance;
		}
		return wholeDistance;
	}

}
